package hfdp.chp05;

/**
 * Created by chei on 2016/3/31.
 */
public class SingletonSync {

    private static SingletonSync uniqueInstance;

    private SingletonSync(){

    }

    /**
     * By adding the synchronized keyword to getInstance(), we force every thread to wait its turn before it can enter the method.
     * That is, no two threads may enter the method at the same time
     * @return
     */
    public static synchronized  SingletonSync getInstance() {
        if(null == uniqueInstance){
            uniqueInstance = new SingletonSync();
        }
        return uniqueInstance;
    }
}
